package cn.jdy.plugins.wap;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.entity.ConfValue;
import cn.jdy.platform.service.ConfService;
import cn.jdy.platform.service.NewsService;
import cn.jdy.plugins.entity.Productx;
import cn.jdy.plugins.service.ProductxService;
 

/**
 * 微门户首页
 * 
 * @author zhaigt
 * @date 2014-08-22
 */
@RestController
@RequestMapping("/")
public class IndexCtrl extends BaseCtrl {
 
  @Autowired
  private NewsService newsService;
	@Autowired
	private ConfService confService;
	
	@Autowired
	private ProductxService productxService;
  /**
   * 首页
   */
  @RequestMapping(value = { "", "/index.html" })
  public ModelAndView index() {
    ModelAndView mv = new ModelAndView(super.t + "/index.jsp");
    try {
		mv.addObject("classList", confService.queryByType(6, 0L));
       //首页放6个产品
		Productx prt=new Productx();
		prt.setIssy("1");
		prt.setiDisplayStart(0);
		prt.setiDisplayLength(6);
		mv.addObject("prList", productxService.query(prt));

 
    } catch (Exception e) {
      BaseLog.e(this.getClass(), "首页数据获取错误", e);
    }
    return mv;
  }

  private List<ConfValue> getMenus() {
    String path = request.getContextPath();
    List<ConfValue> menus = new LinkedList<ConfValue>();
    ConfValue cv0 = new ConfValue();
    cv0.setValue0("代理信息");
    cv0.setValue1(path + "/business");
    cv0.setValue2("/static/img/1.png");
    cv0.setRemark("#d87570");
    menus.add(cv0);

    ConfValue cv2 = new ConfValue();
    cv2.setValue0("家居头条");
    cv2.setValue1(path + "/news");
    cv2.setValue2("/static/img/2.png");
    cv2.setRemark("#118adb");
    menus.add(cv2);

    ConfValue cv3 = new ConfValue();
    cv3.setValue0("营销智库");
    cv3.setValue1(path + "/doc");
    cv3.setValue2("/static/img/3.png");
    cv3.setRemark("#58d2f0");
    menus.add(cv3);

    ConfValue cv4 = new ConfValue();
    cv4.setValue0("热门项目");
    cv4.setValue1(path + "/companyContext");
    cv4.setValue2("/static/img/4.png");
    cv4.setRemark("#febf02");
    menus.add(cv4);

    ConfValue cv5 = new ConfValue();
    cv5.setValue0("在线客服");
    cv5.setValue1("http://wpa.qq.com/msgrd?v=3&uin=498895913&site=qq&menu=yes");
    cv5.setValue2("/static/img/5.png");
    cv5.setRemark("#bc4040");
    menus.add(cv5);

    ConfValue cv6 = new ConfValue();
    cv6.setValue0("我要加盟");
    cv6.setValue1(path + "/business/initJameng");
    cv6.setValue2("/static/img/6.png");
    cv6.setRemark("#ff8b00");
    menus.add(cv6);
    ConfValue cv7 = new ConfValue();
    cv7.setValue0("他要加盟");
    cv7.setValue1(path + "/business/initHeJameng");
    cv7.setValue2("/static/img/7.png");
    cv7.setRemark("#d87570");
    menus.add(cv7);
    ConfValue cv8 = new ConfValue();
    cv8.setValue0("个人中心");
    cv8.setValue1(path + "/member");
    cv8.setValue2("/static/img/8.png");
    cv8.setRemark("#58d2f0");
    menus.add(cv8);

    return menus;
  }

  private List<ConfValue> getBtns() {
    List<ConfValue> menus = new LinkedList<ConfValue>();
    ConfValue cv0 = new ConfValue();
    cv0.setValue1("tel:073112345678");
    cv0.setValue2("icon-phone");
    menus.add(cv0);
    ConfValue cv1 = new ConfValue();
    cv1.setValue1("/map");
    cv1.setValue2("icon-map-marker");
    menus.add(cv1);
    ConfValue cv2 = new ConfValue();
    cv2.setValue1("/message");
    cv2.setValue2("icon-edit");
    menus.add(cv2);
    ConfValue cv3 = new ConfValue();
    cv3.setValue1("/");
    cv3.setValue2("icon-home");
    menus.add(cv3);
    return menus;
  }

  

  /**
   * 404页面
   */
  @RequestMapping("404")
  public ModelAndView notfond() {
    return new ModelAndView(super.t +"/404");
  }

  /**
   * 500页面
   */
  @RequestMapping("500")
  public ModelAndView servicebusy() {
    return new ModelAndView(super.t +"/500");
  }
}
